package principal;

import datos.Validaciones;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author Miguel
 */
public class JIFRegistroPasajeros extends javax.swing.JInternalFrame {

    /**
     * Creates new form RegistroPasajeros
     */
    //Se crean arreglos de tamaño 5 para almacenar cada componente correspondiente a los 5 días de la semana
    JCheckBox[] dias = new JCheckBox[5];
    JComboBox[] patentes = new JComboBox[5];
    JTextField[] salidas = new JTextField[5];
    JTextField[] llegadas = new JTextField[5];
    Validaciones val = new Validaciones();
    public JIFRegistroPasajeros() {
        initComponents();
        //Se asigna cada componente a los elementos de los arreglos
        dias[0] = jCHBLunes;
        dias[1] = jCHBMartes;
        dias[2] = jCHBMiercoles;
        dias[3] = jCHBJueves;
        dias[4] = jCHBViernes;
        patentes[0] = jCBBusLunes;
        patentes[1] = jCBBusMartes;
        patentes[2] = jCBBusMiercoles;
        patentes[3] = jCBBusJueves;
        patentes[4] = jCBBusViernes;
        salidas[0] = jTFSalidaLun;
        salidas[1] = jTFSalidaMar;
        salidas[2] = jTFSalidaMie;
        salidas[3] = jTFSalidaJue;
        salidas[4] = jTFSalidaVie;
        llegadas[0] = jTFLLegadaLun;
        llegadas[1] = jTFLLegadaMar;
        llegadas[2] = jTFLLegadaMie;
        llegadas[3] = jTFLLegadaJue;
        llegadas[4] = jTFLLegadaVie;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTFRutPas = new javax.swing.JTextField();
        jTFNombrePas = new javax.swing.JTextField();
        jTFApoderadoPas = new javax.swing.JTextField();
        jTFDomicilioPas = new javax.swing.JTextField();
        jTFApellidoPas = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jCBColegios = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTFLLegadaLun = new javax.swing.JTextField();
        jTFLLegadaMar = new javax.swing.JTextField();
        jTFLLegadaMie = new javax.swing.JTextField();
        jTFLLegadaJue = new javax.swing.JTextField();
        jTFLLegadaVie = new javax.swing.JTextField();
        jTFSalidaLun = new javax.swing.JTextField();
        jTFSalidaMar = new javax.swing.JTextField();
        jTFSalidaMie = new javax.swing.JTextField();
        jTFSalidaJue = new javax.swing.JTextField();
        jTFSalidaVie = new javax.swing.JTextField();
        jCHBLunes = new javax.swing.JCheckBox();
        jCHBMartes = new javax.swing.JCheckBox();
        jCHBMiercoles = new javax.swing.JCheckBox();
        jCHBJueves = new javax.swing.JCheckBox();
        jCHBViernes = new javax.swing.JCheckBox();
        jLabel6 = new javax.swing.JLabel();
        jCBBusLunes = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jCBBusMartes = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        jCBBusMiercoles = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jCBBusJueves = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        jCBBusViernes = new javax.swing.JComboBox();
        jBGuardar = new javax.swing.JButton();
        jBCancelar = new javax.swing.JButton();

        setClosable(true);
        setResizable(true);
        setTitle("Registro de Pasajeros");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosed(evt);
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos de Pasajero"));

        jLabel1.setText("Rut :");

        jLabel2.setText("Nombre:");

        jLabel3.setText("Apellido:");

        jLabel4.setText("Apoderado:");

        jLabel5.setText("Domicilio:");

        jLabel10.setText("Colegio:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTFRutPas)
                    .addComponent(jTFNombrePas)
                    .addComponent(jTFApellidoPas, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel10))
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTFApoderadoPas)
                    .addComponent(jTFDomicilioPas)
                    .addComponent(jCBColegios, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jTFApoderadoPas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel5))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(14, 14, 14)
                                .addComponent(jTFDomicilioPas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jCBColegios, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTFRutPas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTFNombrePas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(14, 14, 14)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTFApellidoPas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Horarios Asignados"));

        jLabel7.setText("Seleccion de Dias");

        jLabel8.setText("Horarios de LLegada");

        jLabel9.setText("Horarios de Salida");

        jCHBLunes.setText("Lunes");

        jCHBMartes.setText("Martes");

        jCHBMiercoles.setText("Miercoles");

        jCHBJueves.setText("Jueves");

        jCHBViernes.setText("Viernes");

        jLabel6.setText("Bus:");

        jLabel11.setText("Bus:");

        jLabel12.setText("Bus:");

        jLabel13.setText("Bus:");

        jLabel14.setText("Bus:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel7))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jCHBViernes)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel14)
                        .addGap(35, 35, 35)
                        .addComponent(jCBBusViernes, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jCHBJueves)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel13)
                        .addGap(35, 35, 35)
                        .addComponent(jCBBusJueves, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jCHBMiercoles)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
                        .addComponent(jLabel12)
                        .addGap(35, 35, 35)
                        .addComponent(jCBBusMiercoles, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jCHBMartes)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel11)
                        .addGap(35, 35, 35)
                        .addComponent(jCBBusMartes, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jCHBLunes)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel6)
                        .addGap(35, 35, 35)
                        .addComponent(jCBBusLunes, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTFSalidaMar)
                    .addComponent(jTFSalidaMie)
                    .addComponent(jTFSalidaJue)
                    .addComponent(jTFSalidaVie)
                    .addComponent(jTFSalidaLun, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTFLLegadaVie)
                    .addComponent(jTFLLegadaJue)
                    .addComponent(jTFLLegadaMie)
                    .addComponent(jTFLLegadaMar)
                    .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTFLLegadaLun))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTFSalidaLun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCHBLunes)
                    .addComponent(jLabel6)
                    .addComponent(jCBBusLunes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTFLLegadaLun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTFLLegadaMar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTFSalidaMar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCHBMartes)
                    .addComponent(jLabel11)
                    .addComponent(jCBBusMartes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTFLLegadaMie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTFSalidaMie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCHBMiercoles)
                    .addComponent(jLabel12)
                    .addComponent(jCBBusMiercoles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTFLLegadaJue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTFSalidaJue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCHBJueves)
                    .addComponent(jLabel13)
                    .addComponent(jCBBusJueves, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTFLLegadaVie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTFSalidaVie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCHBViernes)
                    .addComponent(jLabel14)
                    .addComponent(jCBBusViernes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jBGuardar.setText("Guardar");
        jBGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBGuardarActionPerformed(evt);
            }
        });

        jBCancelar.setText("Cancelar");
        jBCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jBGuardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jBCancelar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBGuardar)
                    .addComponent(jBCancelar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        //Al momento de mostrar la ventana, se cargan las patentes de los buses en los combobox que las muestras
        try {            
            PreparedStatement pstm = JFPrincipal.con.getConnection().prepareStatement("select patente_bus from bus;");                                   
            ResultSet res = pstm.executeQuery();
            while(res.next()){
                for(int i = 0; i < 5; i++)
                    patentes[i].addItem(res.getString("patente_bus"));
            }       
            res.close(); 
        }catch(SQLException e){
            System.out.println(e);
            JOptionPane.showMessageDialog(this, "No se ha podido conectar con la base de datos","Error de Datos", JOptionPane.ERROR_MESSAGE);
            this.Salir(); //Si no se pueden cargar los datos, se cierra la ventan actual
            return;
        }
        //Luego se cargan los nombres de los colegios en el combobox correspondiente
        try {            
            PreparedStatement pstm = JFPrincipal.con.getConnection().prepareStatement("select nombre_colegio from colegio;");                                  
            ResultSet res = pstm.executeQuery();
            while(res.next()){           
                jCBColegios.addItem(res.getString("nombre_colegio"));
            }         
            res.close(); 
        }catch(SQLException e){
            System.out.println(e);
            JOptionPane.showMessageDialog(this, "No se ha podido conectar con la base de datos","Error de Datos", JOptionPane.ERROR_MESSAGE);
            this.Salir(); //Si no se pueden cargar los datos, se cierra la ventan actual
        }
    }//GEN-LAST:event_formComponentShown

    private void jBGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBGuardarActionPerformed
        //Al guardar los datos del pasajero, tambien se crean registros en la tabla de los traslado por cada día seleccionado
        //Se obtienen los datos de las cajas de texto
        String rut = jTFRutPas.getText();
        String nombre = jTFNombrePas.getText();
        String apellido = jTFApellidoPas.getText();
        String apoderado = jTFApoderadoPas.getText();
        String domicilio = jTFDomicilioPas.getText();
        if (rut.length() == 0 || nombre.length() == 0 || apellido.length() == 0 || apoderado.length() == 0 || domicilio.length() == 0) //Si alguna de las cajas está vacía, se sale del método
        {
            JOptionPane.showMessageDialog(this, "Todos los campos son obligatorios.","Advertencia", JOptionPane.WARNING_MESSAGE);
            return;
        }
        int dias_chequeados = 0; //cantidad de días chequeados
        for (int i = 0; i < 5; i++) //Se revisan los componentes por cada día
        {
            if (dias[i].isSelected()) //Si está chequeado, se revisa el formato de hora
            {
                String h_salida = salidas[i].getText();
                String h_llegada = llegadas[i].getText();
                 //Si la hora de salida y de llegada tienen el formato correcto, se suma 1 al contador de días
                if (val.validarHora(h_salida) && val.validarHora(h_llegada))
                    dias_chequeados++;
            }
        }
        if (dias_chequeados == 0) //Si no se ha marcado ningún día, se sale del método
        {
            JOptionPane.showMessageDialog(this, "Verifique los días seleccionados.","Advertencia", JOptionPane.WARNING_MESSAGE);
            return;
        }
        int colegio = jCBColegios.getSelectedIndex() + 1; //se almacena el índice del colegio
        //Se guardan los datos del pasajero en la base de datos
        try
        {            
            PreparedStatement pstm = JFPrincipal.con.getConnection().prepareStatement("insert into " + 
                    "pasajero (rut_pasajero, codigo_colegio, nombre_pasajero, apellido_pasajero, apoderado_pasajero, domicilio_pasajero) " +
                    " values(?,?,?,?,?,?);");            
            pstm.setString(1, rut);
            pstm.setString(2, String.valueOf(colegio));
            pstm.setString(3, nombre);
            pstm.setString(4, apellido);
            pstm.setString(5, apoderado);
            pstm.setString(6, domicilio); 
            pstm.execute();
            pstm.close();            
         }catch(SQLException e){
             System.out.println(e);
             JOptionPane.showMessageDialog(this, "No se han podido guardar los datos del pasajero en la base de datos.","Error de Datos", JOptionPane.ERROR_MESSAGE);
             return;
         }
        //Luego se guardan los días seleccionados
        for(int i = 0; i < 5; i++)
        {
            if (dias[i].isSelected())
            {
                String h_salida = salidas[i].getText();
                String h_llegada = llegadas[i].getText();
                 //Si la hora de salida o de llegada no tiene el formato correcto, se lo salta
                if (!val.validarHora(h_salida) || !val.validarHora(h_llegada))
                    continue;
                try
                {           
                    PreparedStatement pstm = JFPrincipal.con.getConnection().prepareStatement("insert into " + 
                            "traslado_diario (rut_pasajero, patente_bus, dia_traslado, horasalida_traslado, horallegada_traslado) " +
                            " values(?,?,?,?,?,?);");                         
                    pstm.setString(1, rut);
                    pstm.setString(2, patentes[i].getSelectedItem().toString());
                    pstm.setString(3, String.valueOf(i + 1));
                    pstm.setString(4, salidas[i].getText());
                    pstm.setString(5, llegadas[i].getText()); 
                    pstm.execute();
                    pstm.close();            
                }catch(SQLException e){
                    System.out.println(e);
                    JOptionPane.showMessageDialog(this, "No se han podido guardar todos los traslados en la base de datos.","Error de Datos", JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }
        }
        this.Salir();
    }//GEN-LAST:event_jBGuardarActionPerformed

    private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed
        //El boton Cancelar cierra la ventana actual
        this.Salir();
    }//GEN-LAST:event_jBCancelarActionPerformed

    private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosed
         JFPrincipal.pasajeros = null; //se asigna null a la variable que almacena la ventana actual
    }//GEN-LAST:event_formInternalFrameClosed

    private void Salir()
    {
        this.setVisible(false);
        this.dispose();
        JFPrincipal.pasajeros = null; //se asigna null a la variable que almacena la ventana actual
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBCancelar;
    private javax.swing.JButton jBGuardar;
    private javax.swing.JComboBox jCBBusJueves;
    private javax.swing.JComboBox jCBBusLunes;
    private javax.swing.JComboBox jCBBusMartes;
    private javax.swing.JComboBox jCBBusMiercoles;
    private javax.swing.JComboBox jCBBusViernes;
    private javax.swing.JComboBox jCBColegios;
    private javax.swing.JCheckBox jCHBJueves;
    private javax.swing.JCheckBox jCHBLunes;
    private javax.swing.JCheckBox jCHBMartes;
    private javax.swing.JCheckBox jCHBMiercoles;
    private javax.swing.JCheckBox jCHBViernes;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTFApellidoPas;
    private javax.swing.JTextField jTFApoderadoPas;
    private javax.swing.JTextField jTFDomicilioPas;
    private javax.swing.JTextField jTFLLegadaJue;
    private javax.swing.JTextField jTFLLegadaLun;
    private javax.swing.JTextField jTFLLegadaMar;
    private javax.swing.JTextField jTFLLegadaMie;
    private javax.swing.JTextField jTFLLegadaVie;
    private javax.swing.JTextField jTFNombrePas;
    private javax.swing.JTextField jTFRutPas;
    private javax.swing.JTextField jTFSalidaJue;
    private javax.swing.JTextField jTFSalidaLun;
    private javax.swing.JTextField jTFSalidaMar;
    private javax.swing.JTextField jTFSalidaMie;
    private javax.swing.JTextField jTFSalidaVie;
    // End of variables declaration//GEN-END:variables
}
